package com.culture.config.wrapper;

import com.culture.config.common.util.BeanUtil;
import com.culture.config.dao.entity.User;
import com.culture.config.model.po.*;
import com.culture.config.util.AuthenticationUtil;

import org.apache.commons.lang3.StringUtils;

import lombok.experimental.UtilityClass;

@UtilityClass
public class UserWrapper {
    public static User wrapUserQuery(UserPageParamPO param) {
		User user = new User();	  
		if(StringUtils.isNotBlank(param.getUserName())){
			user.setUserName(param.getUserName());
		}		
		return user;
	}		

	public static User wrapUserAdd(UserAddPO userAddPO) {
		User user = BeanUtil.copyProperties(userAddPO, User.class);	
		user.setUserPassword(AuthenticationUtil.encodePassword(user.getUserPassword()));
		AuthenticationUtil.setInsertFieldInfo(user);
		return user;
	}
	
	public static User wrapUserUpdate(UserUpdatePO userUpdatePO) {
		User user = BeanUtil.copyProperties(userUpdatePO, User.class);
		AuthenticationUtil.setUpdateFieldInfo(user);	
		return user;
	}

	public static User wrapUserPwdUpdate(UserPasswordUpdatePO userPasswordUpdatePO){
		User user = BeanUtil.copyProperties(userPasswordUpdatePO, User.class);
		user.setUserPassword(AuthenticationUtil.encodePassword(user.getUserPassword()));
		AuthenticationUtil.setUpdateFieldInfo(user);	
		return user;
	}
}
